<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>React-Router 简单路由</title>
    <script src="https://cdn.bootcss.com/react/16.2.0/umd/react.production.min.js"></script>
    <script src="https://cdn.bootcss.com/react-dom/16.2.0/umd/react-dom.production.min.js"></script>
    <script src="https://cdn.bootcss.com/react-router-dom/4.2.2/react-router-dom.js"></script>
    <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="app"></div>

<script type="text/babel">
    const {Link,NavLink, BrowserRouter, Route, Switch}= ReactRouterDOM;
    const Router = BrowserRouter;
    class AboutComponent extends React.Component{
        render(){
            return (
                <div>
                    关于React-Router
                </div>
            );
        }
    }
    class HomeComponent extends React.Component{
        render(){
            return (
                <div>
                    首页
                </div>
            );
        }
    }
    class App extends React.Component{
        render(){
            return (
                <Router >
                    <div>
                        <ul style={{ listStyleType: 'none', padding: 0 }}>
                            <li><NavLink to='/home' activeClassName="selected">首页</NavLink></li>
                            <li><NavLink to='/about' >关于</NavLink></li>
                        </ul>
                        <hr/>
                        <Switch>
                            <Route path='/home' component={HomeComponent}/>
                            <Route path='/about' component={AboutComponent}/>
                            <Route component={HomeComponent}/>
                        </Switch>
                    </div>
                </Router>
            )
        }
    }
    ReactDOM.render(
        <App />
        , document.getElementById('app'));
</script>
</body>
</html>